home *** CD-ROM | disk | FTP | other *** search
- Path: goanna.cs.rmit.EDU.AU!not-for-mail
- From: rav@goanna.cs.rmit.EDU.AU (++ robin)
- Newsgroups: comp.lang.pl1,comp.lang.c
- Subject: Re: PL/I and C
- Date: 28 Feb 1996 18:58:03 +1100
- Organization: Comp Sci, RMIT, Melbourne, Australia
- Message-ID: <4h11ub$njp@goanna.cs.rmit.EDU.AU>
- References: <4gh5ru$eng@goanna.cs.rmit.EDU.AU> <312CCEB2.4AB7@corp.dialog.com> <4grhtv$s31@goanna.cs.rmit.EDU.AU> <4gt0tv$826@solutions.solon.com>
- NNTP-Posting-Host: goanna.cs.rmit.edu.au
- X-Newsreader: NN version 6.5.0 #0 (NOV)
-
- seebs@solutions.solon.com (Peter Seebach) writes:
-
- >In article <4grhtv$s31@goanna.cs.rmit.EDU.AU>,
- >++ robin <rav@goanna.cs.rmit.EDU.AU> wrote:
- >>---The basic operations of string-handling are done somewhat
- >>clumsily in C -- catenation is a simple infix operation
- >>in PL/I, but you must use a function in C, and then it
- >>catentates the second operand to the first. Nothing like
- >>c = d || e;
- >>(And what happens when, in strcat(s1, s2), the sum of the lengths
- >>of s1 and s2 exceeds the declaration for s1?!?!?
-
- >Then you invoke undefined behavior, and your code was illegal. :)
-
- >Yes, C's string handling is primitive. It also has no hidden overhead.
-
- ---Well, it DOES have overhead. First there's a procedure call
- and return. That's overhead. Second, to do a catenation,
- C has to search the first string s1, in order to find
- the null terminator, then append the second string s2.
- The search is overhead. The overhead can be high for a
- long string (specially if just one character is appended).
-
- >>---again, for comparison, IF s1 > s2 THEN . . . becomes
- >>strcmp(s1, s2) . . . which yields neg, 0, or pos . . .
- >>which leads to IF strcmp(s1, s2) > 0 . . .
- >>which is scarcely intuitive [shades of the arcane FORTRAN
- >>arithmetic IF].
-
- >I would kill for arithmetic if, simply because I frequently want to do
- >one of three things bsed on the sign of an expression.
-
- ---No need. There's IF and SELECT, which will do the job
- in a much clearer fashion.
-
- >Once again, C has no hidden overhead, but has primitive functions. And?
-
- ---Too right. That's the crux. They are crude, and don't include
- basic checks to see whether the pint pot is full (for example).
-
- >> I'd agree with the statement about built-in functions.
- >>PL/I for AIX and OS/2 now have BIFs for searching for specific
- >>characters (SEARCH) either from the right or from the left,
- >>searching for the absence of specififc characters (VERIFY)
- >>from the right or left.
-
- >strchr, strrchr, strspn, strcspn, strpbrk.
-
- ---strchr searches for just one character. VERIFY searches for
- up to 255 characters. SEARCH searches for up to 255 charcters.
- As for the others (strrchr etc), they are not in all systems.
- In other words, strchr is a trivial function that can be written
- as a compact search in PL/I even without using a function.
-
- >> Furthermore INDEX, SEARCH, SEARCHR, VERIFY and VERIFYR
- >>can start the search at any specified position (the three-
- >>argument versions).
-
- >Same functions in C, you just use (s + 2) to start 2 positions in. :)
-
- ---They're not. See above.
-
- >> There are several functions for centering text, & trimming
- >>given characters from either or both ends of a string.
-
- >sprintf.
-
- ---Not quite. The above are non-I/O functions.
-
- >> And what happens when you actually w*a*n*t a zero byte in your
- >>C character string?
-
- >All C character strings have a zero byte in them. It's at the end.
- >(But it *is* a part of the string, so far as I can tell.)
-
- >If you want an object which has characters possibly including NUL bytes,
- >but is otherwise like a string, feel free to make one; it's trivial.
- >It's just more expensive to run.
-
- ---How is it trivial?
-
- >This is silly, though. C is a low-level language by modern standards.
- >So? It's a design call. You choose a language that meets your needs. C
- >meets my needs because it's available for the machines I want to use.
-
- >Let's try to keep the inter-language flame wars at a minimum, and if nothing
- >else, let's try to keep it so that only people who know C very well and are
- >comfortable with the whole library are discussing C's merits, and ditto
- >for PL/I. I certainly don't have the qualifications to bash PL/I, and I doubt
- >you have the qualifications to bash C. :)
-
- >(I can bash C, I just don't really want to.)
-
- >Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- >C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
-